<template>
  <div class="page">
    <p class="receivelist">收货单列表</p>

    <div class="header">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="验收状态">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option label="未配送" value="0"></el-option>
            <el-option label="已配送" value="1"></el-option>
            <el-option label="已验收" value="2"></el-option>
            <el-option label="全部" value=""></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收货日期">
          <el-date-picker
            v-model="formInline.deliveryDate"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table">
      <el-table
        :data="receiveLists"
        border
        style="width: 100%;text-align:center"
      >
        <el-table-column type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column prop="deliveryId" label="收货单号"> </el-table-column>
        <el-table-column prop="supplierShortName" label="供应商简称">
        </el-table-column>
        <el-table-column prop="deliveryTypeNum" label="品种数量">
        </el-table-column>
        <el-table-column prop="totalWeight" label="总重量"> </el-table-column>
        <el-table-column prop="totalPrice" label="总金额"> </el-table-column>
        <el-table-column prop="deliveryDate" label="收货日期">
        </el-table-column>
        <el-table-column prop="deliveryStatus" label="验收状态">
          <template slot-scope="scope">
            {{ scope.row.deliveryStatus | statusFitlter }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="200px">
          <template slot-scope="scope">
            <el-button
              type="primary"
              @click="receivedetail(scope.row.deliveryId)"
              >明细</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页数据 -->
    <el-pagination
      @current-change="handleCurrentChange"
      background
      :current-page="pagenum"
      :page-size="pagesize"
      layout="prev,pager,next"
      :total="total - 0"
      style="margin-top:20px;text-align:center"
    ></el-pagination>
  </div>
</template>

<script>
import { getreceiveList } from "@/api/receive.js";
export default {
  filters: {
    statusFitlter(value) {
      if (value === 0) {
        return "未配送";
      } else if (value === 1) {
        return "已配送";
      } else if (value === 2)  {
        return "已验收";
      }
    }
  },
  data() {
    return {
      formInline: {
        deliveryDate: "",
        status: ""
      },
      receiveLists: [],
      // 显示第几页
      pagenum: 1,
      total: "",
      // 每页显示的数据
      pagesize: 10
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    // 当前第几页
    handleCurrentChange(val) {
      this.pagenum = val;
      this.init();
    },
    init() {
      var data = {
        deliveryDate: this.formInline.deliveryDate,
        status: this.formInline.status,
        pageNo: this.pagenum
      };
      // 获取收货单列表
      getreceiveList(data)
        .then(res => {
          console.log(res);
          console.log(data);
          if (res.code === 20000) {
            this.receiveLists = res.rows;
            this.total = res.total;
            this.pagesize = res.pageSize
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    receivedetail(id) {
      this.$router.push({
        path: "shouhuo_minxi",
        query: { deliveryId: id }
      });
    },
    // 搜索查询
    search() {
      this.init();
    }
  }
};
</script>

<style lang="scss" scoped>
.page {
  padding: 20px 20px;
  .receivelist {
    font-size: 22px;
    margin-bottom: 60px;
  }
  .header {
    margin-bottom: 70px;
  }
}
</style>
